package com.ruoyi.his.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.his.domain.NewHisRegistration;
import com.ruoyi.his.service.INewHisRegistrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.his.mapper.HisTreatMapper;
import com.ruoyi.his.domain.HisTreat;
import com.ruoyi.his.service.IHisTreatService;

/**
 * 就诊Service业务层处理
 *
 * @author 吴绍艳
 * @date 2025-03-31
 */
@Service
public class HisTreatServiceImpl implements IHisTreatService
{
    @Autowired
    private HisTreatMapper hisTreatMapper;
    @Autowired
    private INewHisRegistrationService newHisRegistrationService;

    /**
     * 查询就诊
     *
     * @param treatId 就诊主键
     * @return 就诊
     */
    @Override
    public HisTreat selectHisTreatByTreatId(Long treatId)
    {
        return hisTreatMapper.selectHisTreatByTreatId(treatId);
    }

    /**
     * 查询就诊列表
     *
     * @param hisTreat 就诊
     * @return 就诊
     */
    @Override
    public List<HisTreat> selectHisTreatList(HisTreat hisTreat)
    {
        return hisTreatMapper.selectHisTreatList(hisTreat);
    }

    /**
     * 新增就诊
     *
     * @param hisTreat 就诊
     * @return 结果
     */
    @Transactional
    @Override
    public Long insertHisTreat(HisTreat hisTreat)
    {
        hisTreat.setCreateTime(DateUtils.getNowDate());
        int rows = hisTreatMapper.insertHisTreat(hisTreat);
        Long treatId = hisTreat.getTreatId();
        NewHisRegistration newHisRegistration =new NewHisRegistration();
        newHisRegistration.setRegistrationId(hisTreat.getQueueId());
        newHisRegistration.setTreatId(treatId);
        newHisRegistrationService.updateNewHisRegistration(newHisRegistration);
        return treatId;
    }

    /**
     * 修改就诊
     *
     * @param hisTreat 就诊
     * @return 结果
     */
    @Transactional
    @Override
    public int updateHisTreat(HisTreat hisTreat)
    {
        hisTreat.setUpdateTime(DateUtils.getNowDate());
        return hisTreatMapper.updateHisTreat(hisTreat);
    }

    /**
     * 批量删除就诊
     *
     * @param treatIds 需要删除的就诊主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteHisTreatByTreatIds(Long[] treatIds)
    {

        return hisTreatMapper.deleteHisTreatByTreatIds(treatIds);
    }

    /**
     * 删除就诊信息
     *
     * @param treatId 就诊主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteHisTreatByTreatId(Long treatId)
    {
        return hisTreatMapper.deleteHisTreatByTreatId(treatId);
    }

}
